<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div style="width:30%;margin:200px auto;border:1px solid #000">
<input type="radio" name="flag" value="0"/>管理员登录
<input type="radio" name="flag" value="1"/>教师登录
<input type="radio" name="flag" value="2"/>学生登录
</br>
学号/工号:<input type="text" id="number" style="margin-top:20px">
</br>
&nbsp;&nbsp;&nbsp;密码:<input type="password" id="password" style="margin-left:25px;margin-top:25px">
<input type="button" value="确认登陆" style="width:90px;height:27px;margin-top:30px;margin-left:100px;margin-bottom:20px" onclick="get()">
</div>
</body>
<script> 
function get(){
	// ajax ---》 利用ajax进行数据提交  // ++ http协议
	var url = "http://localhost:8080/qcbycoursehelper/LoginServlet"; 
	var data ={
			"number":$("#number").val(),
			"password":$("#password").val(),
			"flag":$('input[name="flag"]:checked').val()
	}
	$.ajax({
        type:"post",//指定提交的类型，get对应doget(),post对应dopost()
        url:url,   // 地址
        data:data,//data代表key -value类型的数据  
        dataType:'JSON', //定义数据的类型
        success: function (value)//success、error代表是否返回成功
        {
        	//alert("aaa");
        	console.log(value.message);
        	if(value.message=="查询成功"){
        		function getCookie(cname){
        		    var name = cname + "=";
        		    var ca = document.cookie.split(';');
        		    for(var i=0; i<ca.length; i++) {
        		        var c = ca[i].trim();
        		        if (c.indexOf(name)==0) { return c.substring(name.length,c.length); }
        		    }
        		    return "";
        		}
        		var flag = getCookie("flag");
        		if(flag==0){
        			window.location.href="http://localhost:8080/qcbycoursehelper/admin.html";
        		}else if(flag==2){
        			window.location.href="http://localhost:8080/qcbycoursehelper/student.html";
        		}else{
        			window.location.href="http://localhost:8080/qcbycoursehelper/teacher.html";
        		}
        	}
        },
        error:function (XMLHttpRequest, textStatus, errorThrown) { 
            alert(typeof(errorThrown));
        }
     });
}
</script>
</html>